package com.idea.cery.springboot1.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @Author:cery
 * @Version 1.0
 * @Date:2020/4/9
 */
@WebListener
public class MyServletContextListener implements ServletContextListener, HttpSessionListener {
    /**
     * 系统监听
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("系统启动加载系统配置...");

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // TODO Auto-generated method stub
        System.out.println("关闭系统...");
    }

    /**
     * 用户回话监听
     */
    @Override
    public void sessionCreated(HttpSessionEvent she) {
        //调用 *.getSession().getId() 方法 先进该方法
        System.out.println("Session build: " + she.getSession());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent she) {

        System.out.println("Session destory: " + she.getSession());
    }
}
